package com.main.controller;

import cloud.api.pojo.Payment;
import cloud.api.pojo.Result;
import com.main.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author zw
 * @date 2022-08-20.
 */
@RestController
@Slf4j
@RequestMapping("Payment")
public class PaymentController {

    @Autowired
    public PaymentService paymentServiceImpl;
    @Value("${server.port}")
    public String serverPost;

    @PostMapping("create")
    public Result create(@RequestBody Payment payment){
        int result =  paymentServiceImpl.create(payment);
        log.info("***插入结果****" + result);
        if (result<=0)
            return  new Result(444,"插入失败"+" -- post:"+serverPost);
        else
            return new Result(200,"插入成功"+" -- post:"+serverPost,result);
    }
    @GetMapping("getPaymentById/{id}")
    public Result PaymentById(@PathVariable("id") Long id){
        Payment payment = paymentServiceImpl.getPaymentById(id);
        log.info("***发生查询*** --id = " + id);
        if (payment!=null)
            return new Result(200,"查询成功"+" -- post:"+serverPost,payment);
        else
            return new Result(444,"查询失败"+" -- post:"+serverPost);
    }

}